/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufc.quixada.adrs.service;

import br.ufc.quixada.adrs.dao.SupervisorDAO;
import br.ufc.quixada.adrs.model.Supervisor;
import br.ufc.quixada.adrs.util.Msg;
import br.ufc.quixada.adrs.util.UtilAdrs;
import java.sql.SQLException;
import org.slf4j.LoggerFactory;

/**
 *
 * @author Franklin
 */
public class SupervisorService {

    private final SupervisorDAO supervisorDAO = new SupervisorDAO();

    public boolean insertSupervisor(Supervisor supervisor) {
        try {
            UtilAdrs.upperCase(supervisor);
            supervisorDAO.insert(supervisor);
            return true;
        } catch (SQLException ex) {
            LoggerFactory.getLogger(this.getClass()).error(Msg.EXCEPTION_MESSAGE, this.getClass().getSimpleName(), ex);
            return false;
        }
    }

    public boolean updateSupervisor(Supervisor supervisor) {
        try {
            UtilAdrs.upperCase(supervisor);
            supervisorDAO.update(supervisor);
            return true;
        } catch (SQLException ex) {
            LoggerFactory.getLogger(this.getClass()).error(Msg.EXCEPTION_MESSAGE, this.getClass().getSimpleName(), ex);
            return false;
        }
    }

    public boolean deleteSupervisor(Long id) {
        try {
            supervisorDAO.delete(id);
            return true;
        } catch (SQLException ex) {
            LoggerFactory.getLogger(this.getClass()).error(Msg.EXCEPTION_MESSAGE, this.getClass().getSimpleName(), ex);
            return false;
        }
    }

    public Supervisor getSupervisorByUsuarioId(Long id) {
        try {
            Supervisor supervisor = supervisorDAO.getByUsuarioId(id);
            if (supervisor == null) {
                return null;
            } else {
                return supervisor;
            }
        } catch (SQLException ex) {
            LoggerFactory.getLogger(this.getClass()).error(Msg.EXCEPTION_MESSAGE, this.getClass().getSimpleName(), ex);
            return null;
        }
    }

    public Supervisor getSupervisorById(Long id) {
        try {
            Supervisor supervisor = supervisorDAO.getById(id);
            if (supervisor == null) {
                return null;
            } else {
                return supervisor;
            }
        } catch (SQLException ex) {
            LoggerFactory.getLogger(this.getClass()).error(Msg.EXCEPTION_MESSAGE, this.getClass().getSimpleName(), ex);
            return null;
        }
    }
}
